// Copyright (C) 2010 Johan Rende.

//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

//	Official SVN repository and contact information can be found at
//	https://code.google.com/p/lt-engine/

package jwjgl;

import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class GameDisplay {
	

	
	public static void initGL() {

		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		
	    GL11.glMatrixMode(GL11.GL_PROJECTION);
	    GL11.glLoadIdentity();
	    
	    
	    GL11.glMatrixMode(GL11.GL_MODELVIEW);
	    GL11.glLoadIdentity();
	    GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
	    GL11.glOrtho(800, 0.0f, 0.0f, 600, -1.0, 1.0);
	   
	    GL11.glEnable(GL11.GL_TEXTURE_2D);
	    
	    
	    GL11.glEnable(GL11.GL_ALPHA_TEST);
	    GL11.glAlphaFunc(GL11.GL_GREATER,0.1f);

	}
	
	public static void initscr(int targetWidth, int targetHeight){
			// in this case we only care about the dimensions of the screen, we're aiming
			// for an 800x600 display.	
	
			DisplayMode chosenMode = null;
	
			try {
				DisplayMode[] modes = Display.getAvailableDisplayModes();
	
				for (int i=0;i<modes.length;i++) {
					if ((modes[i].getWidth() == targetWidth) && (modes[i].getHeight() == targetHeight)) {
						chosenMode = modes[i];
						break;
					}
				}
			} catch (LWJGLException e) {     
				Sys.alert("Error", "Unable to determine display modes.");
				System.exit(0);
			}
	
			// at this point if we have no mode there was no appropriate, let the user know 
			// and give up...
			if (chosenMode == null) {
				Sys.alert("Error", "Unable to find appropriate display mode.");
				System.exit(0);
			}
	
	
			try {
				Display.setDisplayMode(chosenMode);
				Display.setTitle("LWJGL-Spel");
				Display.create();
				initGL();
				
	
			} catch (LWJGLException e) {
				Sys.alert("panik!", "Unable to create display.");
				System.exit(0);
			}

				try {
					Mouse.create();
				} catch (LWJGLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					Sys.alert("Mus", "musen hittades inte...");
				}
			
	
			// go on to do any initialisation of OpenGL here, for example loading textures
			// or setting up basic global settings 
	
		}
}



